/*
 * BotView.java
 *
 * Created on 25-01-2010, 18:46:37
 */

package gui;

import ircbot.Bot;
import ircbot.Log;
import util.Observer;

/**
 *
 * @author andreas
 */
public class GuiView extends javax.swing.JFrame implements Observer {
    GuiController controller;
    Bot model;

    /** Creates new form BotView */
    public GuiView(Bot model) {
        this.model = model;
        model.addObserver(this);
        this.controller = new GuiController(model, this);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        inputText = new javax.swing.JTextField();
        inputButton = new javax.swing.JButton();
        comboChannel = new javax.swing.JComboBox();
        panelOut = new javax.swing.JPanel();
        lableOut = new javax.swing.JLabel();
        panelLog = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        outputText = new javax.swing.JTextArea();
        JobPanel = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jobTree = new javax.swing.JTree();
        jMenuBar1 = new javax.swing.JMenuBar();
        settingsMenu = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("ismBOT gui");

        inputText.setText("insert command here");

        inputButton.setText("Send");
        inputButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                inputButtonActionPerformed(evt);
            }
        });

        comboChannel.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        panelOut.setBorder(javax.swing.BorderFactory.createTitledBorder("Output"));

        lableOut.setFont(new java.awt.Font("DejaVu Sans", 2, 13));
        lableOut.setForeground(new java.awt.Color(30, 30, 227));
        lableOut.setText("Output");

        javax.swing.GroupLayout panelOutLayout = new javax.swing.GroupLayout(panelOut);
        panelOut.setLayout(panelOutLayout);
        panelOutLayout.setHorizontalGroup(
            panelOutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelOutLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lableOut, javax.swing.GroupLayout.DEFAULT_SIZE, 615, Short.MAX_VALUE)
                .addContainerGap())
        );
        panelOutLayout.setVerticalGroup(
            panelOutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelOutLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lableOut, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        panelLog.setBorder(javax.swing.BorderFactory.createTitledBorder("Channel Log"));

        outputText.setColumns(20);
        outputText.setEditable(false);
        outputText.setRows(5);
        jScrollPane1.setViewportView(outputText);

        javax.swing.GroupLayout panelLogLayout = new javax.swing.GroupLayout(panelLog);
        panelLog.setLayout(panelLogLayout);
        panelLogLayout.setHorizontalGroup(
            panelLogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelLogLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 627, Short.MAX_VALUE)
                .addContainerGap())
        );
        panelLogLayout.setVerticalGroup(
            panelLogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelLogLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
                .addContainerGap())
        );

        JobPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Job info"));

        jScrollPane2.setViewportView(jobTree);

        javax.swing.GroupLayout JobPanelLayout = new javax.swing.GroupLayout(JobPanel);
        JobPanel.setLayout(JobPanelLayout);
        JobPanelLayout.setHorizontalGroup(
            JobPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JobPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
                .addContainerGap())
        );
        JobPanelLayout.setVerticalGroup(
            JobPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JobPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 426, Short.MAX_VALUE)
                .addContainerGap())
        );

        settingsMenu.setText("Settings");
        jMenuBar1.add(settingsMenu);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(panelLog, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(panelOut, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(inputText, javax.swing.GroupLayout.PREFERRED_SIZE, 402, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(comboChannel, 0, 186, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(inputButton)))
                .addGap(18, 18, 18)
                .addComponent(JobPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JobPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(inputButton)
                                .addComponent(comboChannel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(inputText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(6, 6, 6)
                        .addComponent(panelOut, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(panelLog, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void inputButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inputButtonActionPerformed
        controller.injectCommand(inputText.getText(), (String)comboChannel.getSelectedItem());
    }//GEN-LAST:event_inputButtonActionPerformed

    /*
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new BotView().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel JobPanel;
    private javax.swing.JComboBox comboChannel;
    private javax.swing.JButton inputButton;
    private javax.swing.JTextField inputText;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTree jobTree;
    private javax.swing.JLabel lableOut;
    private javax.swing.JTextArea outputText;
    private javax.swing.JPanel panelLog;
    private javax.swing.JPanel panelOut;
    private javax.swing.JMenu settingsMenu;
    // End of variables declaration//GEN-END:variables

    protected void setOutMessage(String message) {
        lableOut.setText(message);
    }

    public void update() {
        //updating log
        Log log = model.getLog();
        outputText.setText(log.getLog());

        //updating channels
        comboChannel.removeAllItems();

        String[] channels = model.getChannels();
        for(int i = 0; i < channels.length; i++) {
            comboChannel.addItem(channels[i]);
        }

        //updating jobs
       
    }

}
